package com.xsf.jieyou.cloud.service;

import com.xsf.jieyou.cloud.api.CloudMongoDbUserLogService;
import com.xsf.jieyou.commons.entity.UserLog;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户日志 MongoDB 接口实现类。
 *
 * @author xsf
 * @version v1.0.0
 * @date 2019/12/22 0022 13:04
 * @see com.xsf.jieyou.cloud.service
 **/
@Service(version = "1.0.0")
public class CloudMongoDbUserLogServiceImpl implements CloudMongoDbUserLogService {
    @Resource
    private MongoTemplate mongoTemplate;

    /**
     * 新增
     *
     * @param userLog {@link UserLog}
     */
    @Override
    public void insert(UserLog userLog) {
        System.out.println(mongoTemplate);
        System.out.println(userLog);
        this.mongoTemplate.insert(userLog);
    }

    /**
     * 查询
     *
     * @return UserLog {@link UserLog}
     */
    @Override
    public UserLog selectOneById(Long id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(id));
        return this.mongoTemplate.findOne(query, UserLog.class);
    }

    /**
     * 查询所有
     *
     * @return List<UserLog> {@link List<UserLog>}
     */
    @Override
    public List<UserLog> selectAll() {
        return this.mongoTemplate.findAll(UserLog.class);
    }
}
